package thoven.achievement.net.ideapluginachievement.action

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.Messages
import thoven.achievement.net.ideapluginachievement.service.ReportType
import thoven.achievement.net.ideapluginachievement.ui.ReportDialog

/**
 * 显示报告对话框的操作
 */
class ShowReportAction : AnAction() {
    
    private val LOG = logger<ShowReportAction>()
    
    override fun actionPerformed(e: AnActionEvent) {
        val project = e.project ?: return
        
        LOG.info("显示报告对话框")
        try {
            // 显示日报对话框
            val dialog = ReportDialog(project)
            dialog.show()
        } catch (e: Exception) {
            LOG.error("显示报告对话框出错", e)
            Messages.showErrorDialog(
                project,
                "显示报告对话框出错: ${e.message}",
                "错误"
            )
        }
    }
}

/**
 * 显示日报对话框的操作
 */
class ShowDailyReportAction : AnAction() {
    
    private val LOG = logger<ShowDailyReportAction>()
    
    override fun actionPerformed(e: AnActionEvent) {
        val project = e.project ?: return
        
        LOG.info("显示日报对话框")
        try {
            // 显示日报对话框
            val dialog = ReportDialog(project, ReportType.DAILY)
            dialog.show()
        } catch (e: Exception) {
            LOG.error("显示日报对话框出错", e)
            Messages.showErrorDialog(
                project,
                "显示日报对话框出错: ${e.message}",
                "错误"
            )
        }
    }
}

/**
 * 显示周报对话框的操作
 */
class ShowWeeklyReportAction : AnAction() {
    
    private val LOG = logger<ShowWeeklyReportAction>()
    
    override fun actionPerformed(e: AnActionEvent) {
        val project = e.project ?: return
        
        LOG.info("显示周报对话框")
        try {
            // 显示周报对话框
            val dialog = ReportDialog(project, ReportType.WEEKLY)
            dialog.show()
        } catch (e: Exception) {
            LOG.error("显示周报对话框出错", e)
            Messages.showErrorDialog(
                project,
                "显示周报对话框出错: ${e.message}",
                "错误"
            )
        }
    }
}

/**
 * 显示月报对话框的操作
 */
class ShowMonthlyReportAction : AnAction() {
    
    private val LOG = logger<ShowMonthlyReportAction>()
    
    override fun actionPerformed(e: AnActionEvent) {
        val project = e.project ?: return
        
        LOG.info("显示月报对话框")
        try {
            // 显示月报对话框
            val dialog = ReportDialog(project, ReportType.MONTHLY)
            dialog.show()
        } catch (e: Exception) {
            LOG.error("显示月报对话框出错", e)
            Messages.showErrorDialog(
                project,
                "显示月报对话框出错: ${e.message}",
                "错误"
            )
        }
    }
}

/**
 * 报告操作组
 */
class ReportActionGroup : DefaultActionGroup() {
    
    override fun update(e: AnActionEvent) {
        e.presentation.isEnabledAndVisible = e.project != null
    }
} 